home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 17 / AMIGAplus Sonderheft 17 (1999)(ICP)(DE)[!].iso / PD / Anwendungen / ToolManager / Source / WBStartup / toolmanager.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  5KB  |  178 lines

  1. /*
  2.  * toolmanager.c  V3.1
  3.  *
  4.  * ToolManager starter
  5.  *
  6.  * Copyright (C) 1990-98 Stefan Becker
  7.  *
  8.  * This source code is for educational purposes only. You may study it
  9.  * and copy ideas or algorithms from it for your own projects. It is
  10.  * not allowed to use any of the source codes (in full or in parts)
  11.  * in other programs. Especially it is not allowed to create variants
  12.  * of ToolManager or ToolManager-like programs from this source code.
  13.  *
  14.  */
  15.  
  16. #include "toolmanager.h"
  17.  
  18. #ifdef DEBUG
  19. /* Global data */
  20. struct Library *SysBase = NULL; /* For debugging routines */
  21. #endif
  22.  
  23. /* Local function prototypes */
  24. static int Starter(void);
  25.  
  26. /* Entry point (first in code hunk) */
  27. static __geta4 int Entry(void)
  28. {
  29.  /* Call the real code */
  30.  return(Starter());
  31. }
  32.  
  33. /* Local data (second in code hunk) */
  34. static const struct TagItem CatalogParams[] = {
  35.  OC_BuiltInLanguage, (ULONG) "english",
  36.  OC_Version,         TMCATALOGVERSION,
  37.  TAG_DONE
  38. };
  39. static const char VersionString[]           = "$VER: ToolManager_Starter "
  40.                                               TMVERSION
  41.                                               " (" __COMMODORE_DATE__ ")";
  42. static struct EasyStruct Requester          = {
  43.  sizeof(struct EasyStruct), 0, "ToolManager",
  44.  LOCALE_WBSTARTUP_REQUESTER_TEXT_STR, LOCALE_WBSTARTUP_REQUESTER_GADGET_STR
  45. };
  46.  
  47. /* The real code */
  48. #define DEBUGFUNCTION Starter
  49. static int Starter(void)
  50. {
  51. #ifndef DEBUG
  52.  struct Library *SysBase;          /* For production code */
  53. #endif
  54.  struct Message *WBStartup       = NULL;
  55.  struct Task    *HandlerTask;
  56.  struct Library *ToolManagerBase;
  57.  ULONG           rc              = RETURN_FAIL;
  58.  
  59.  /* Initialize SysBase */
  60.  SysBase = *((struct Library **) 4);
  61.  
  62.  /* Retrieve Workbench startup message */
  63.  {
  64.   struct Process *pr = (struct Process *) FindTask(NULL);
  65.  
  66.   /* Started from CLI or Workbench? */
  67.   if (pr->pr_CLI == NULL) {
  68.  
  69.    /* Started from Workbench, wait for the startup message */
  70.    WaitPort(&pr->pr_MsgPort);
  71.  
  72.    /* Retrieve message */
  73.    WBStartup = GetMsg(&pr->pr_MsgPort);
  74.   }
  75.  }
  76.  
  77.  INITDEBUG(ToolManagerStarterDebug)
  78.  
  79.  /* Find ToolManager handler task */
  80.  Forbid();
  81.  HandlerTask = FindTask(TMHANDLERNAME);
  82.  Permit();
  83.  
  84.  MAIN_LOG(LOG1(Handler Task, "0x%08lx", HandlerTask))
  85.  
  86.  /* Now open the toolmanager library */
  87.  if (ToolManagerBase = OpenLibrary(TMLIBNAME, 0)) {
  88.  
  89.   MAIN_LOG(LOG1(ToolManager Library, "0x%08lx", ToolManagerBase))
  90.  
  91.   /* Reset error code */
  92.   rc = RETURN_OK;
  93.  
  94.   /* Handler active? Yes, call quit function */
  95.   if (HandlerTask) {
  96.    BOOL quit = TRUE;
  97.  
  98.    MAIN_LOG(LOG0(Handler active -> stop it))
  99.  
  100.    /* Was our process started from CLI or Workbench? */
  101.    if (WBStartup) {
  102.     struct Library *IntuitionBase;
  103.  
  104.     MAIN_LOG(LOG0(Started from Workbench))
  105.  
  106.     /* We were started from Workbench -> Create an Intuition EasyRequest */
  107.     if (IntuitionBase = OpenLibrary("intuition.library", 39)) {
  108.      struct Library *LocaleBase;
  109.      struct Catalog *Catalog;
  110.  
  111.      MAIN_LOG(LOG1(Intuition Library, "0x%08lx", IntuitionBase))
  112.  
  113.      /* Try to open locale.library */
  114.      if (LocaleBase = OpenLibrary("locale.library", 38)) {
  115.       MAIN_LOG(LOG1(Locale Library, "0x%08lx", LocaleBase))
  116.  
  117.       /* Try to get catalog for current language */
  118.       if (Catalog = OpenCatalogA(NULL, TMCATALOGNAME, CatalogParams)) {
  119.  
  120.        MAIN_LOG(LOG1(Catalog, "0x%08lx", Catalog))
  121.  
  122.        /* Localize strings */
  123.        Requester.es_TextFormat   = GetCatalogStr(
  124.                                              Catalog,
  125.                                              LOCALE_WBSTARTUP_REQUESTER_TEXT,
  126.                                              Requester.es_TextFormat);
  127.        Requester.es_GadgetFormat = GetCatalogStr(
  128.                                              Catalog,
  129.                                              LOCALE_WBSTARTUP_REQUESTER_GADGET,
  130.                                              Requester.es_GadgetFormat);
  131.       }
  132.      }
  133.  
  134.      MAIN_LOG(LOG0(Showing requester))
  135.  
  136.      /* Show requester */
  137.      quit = EasyRequestArgs(NULL, &Requester, NULL, NULL) ? TRUE : FALSE;
  138.  
  139.      /* Locale library open? */
  140.      if (LocaleBase) {
  141.  
  142.       /* Yes, free catalog */
  143.       if (Catalog) CloseCatalog(Catalog);
  144.  
  145.       /* Close library */
  146.       CloseLibrary(LocaleBase);
  147.      }
  148.  
  149.      /* Close Intution */
  150.      CloseLibrary(IntuitionBase);
  151.     }
  152.    }
  153.  
  154.    MAIN_LOG(LOG1(Stopping handler, "%ld", quit))
  155.  
  156.    /* Should we stop the handler? */
  157.    if (quit) QuitToolManager();
  158.   }
  159.  
  160.   /* Close library again */
  161.   CloseLibrary(ToolManagerBase);
  162.  }
  163.  
  164.  MAIN_LOG(LOG1(Result, "%ld", rc))
  165.  
  166.  /* Workbench startup message valid? */
  167.  if (WBStartup) {
  168.  
  169.   /* Yes, disable multitasking */
  170.   Forbid();
  171.  
  172.   /* Reply message */
  173.   ReplyMsg(WBStartup);
  174.  }
  175.  
  176.  return(rc);
  177. }
  178.